// let server_url='http://yifujia.eplusskin.com/';//请求地址
// process.env.NODE_ENV === 'http://yifujia.eplusskin.com/' ; //环境配置
let server_url = 'https://wenzhen.fuerle168.com/'; //请求地址
process.env.NODE_ENV === 'https://wenzhen.fuerle168.com/'; //环境配置

function service(options = {}) {
  let token = uni.getStorageSync('user_info').token; //凭证 
  options.url = `${server_url}${options.url}`;
  //配置请求头
  options.header = {
    'content-type': 'application/x-www-form-urlencoded',
    'Token': `${token}` //Bearer 
  };

  return new Promise((resolved, rejected) => {

    //成功
    options.success = (res) => {
      uni.hideLoading()
      if (res.data.code == 1) { //请求成功
        resolved(res.data);
      } else if (res.data.code == 401) {
        uni.removeStorageSync('user_info');

        uni.reLaunch({
          url: '/pages/login/login'
        })
      } else {
        uni.showToast({
          icon: 'none',
          duration: 3000,
          title: `${res.data.msg}`
        });
        // rejected(res.data.msg);//错误
      }
      // resolved(res.data);

    }
    //错误
    options.fail = (err) => {
      uni.hideLoading()
      rejected(err); //错误
    }
    uni.request(options);

  });
}
export default service;